{extend name="admininfo/admininfo" /}
{block name='main'}

   
   
        <h2>添加歌曲</h2>   
            <form class="form-horizontal" action="{:url('admin/Musics/add')}" method='post' enctype="multipart/form-data">
                    <table class="table table-bordered">
                        <tr>
                            <td>歌曲名</td>
                            <td><input type="text" name='name' id='name'></td>
                        </tr>
                        <tr>
                            <td>演唱歌手</td>
                            <td><input type="text" id='singer' name='singer'></td>
                        </tr>
                        <tr>
                            <td>所属专辑</td>
                            <td>
                                <input type="text" name='specials' id='specials'>
                            </td>
                        </tr>
                        <tr>
                            <td>图片</td>
                            <td><input type="file" name='image'></td>
                        </tr>
                        <tr>
                            <td>音乐</td>
                            <td><input type="text" name='music'></td>
                        </tr>
                        <tr>
                            <td>歌词</td>
                            <td>
                                <input type="file" name='lyrics'>
                            </td>
                        </tr>
                        <tr>
                            <td>标签</td>
                            <td>
                                {foreach $list as $v}
                                    <select name="{$v['id']}" id="">
                                      <optgroup label="{$v['name']}">
                                          {foreach $v['type'] as $vv}
                                                <option value="{$vv['id']}">{$vv['name']}</option>                                       
                                            {/foreach}
                                          
                                        </optgroup>

                                    </select>
                               
                                {/foreach}
                            </td>
                        </tr>
                    </table>  
            
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
                <button class="btn btn-primary adds">
                    保存
                </button>
            </div>
            </form>

<script>
    $(function(){
 //添加专辑是获取歌手
 $("#singer").blur(function(){
     var singer = $('#singer').val();
     $.ajax({
         type:'post',
         url:  '/admin/Specials/singer',
         data:{ 'singer': singer },
         dataType:'json',
         success:function(data){
             // console.log($(this).parents('tr').remove());
             if (data===null) {
              // $("#singer").css("border","1px solid red");
              var HTM = "<b style='color:red'>数据库无此歌手请添加</b>"
              $('#singer').after(HTM)
             }
             
         }

     })

 });

 $("#singer").focus(function(){ 
     $('#singer').next().remove()
 }); 


 $("#specials").blur(function(){
     var specials = $('#specials').val();
     $.ajax({
         type:'post',
         url:  '/admin/Musics/specials',
         data:{ 'specials': specials },
         dataType:'json',
         success:function(data){
             // console.log($(this).parents('tr').remove());
             if (data===null) {
              // $("#singer").css("border","1px solid red");
              var HTM = "<b style='color:red'>数据库无此专辑请添加</b>"
              $('#specials').after(HTM)
             }
             
         }

     })

 });

 $("#specials").focus(function(){ 
     $('#specials').next().remove()
 }); 


    })

</script>

{/block}